package cn.itcast.service.impl;

import cn.itcast.dao.StandardDao;
import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Map;

//收派标准类
@Service
public class StandarServiceImpl implements StandardService {

    @Autowired
    private StandardDao standardDao;

    //增加
    @Override
    @Transactional
    public void save(Standard standard) {

        Standard save = standardDao.save(standard);
        System.out.println("save------ = " + save);
    }


    //分页查询
    @Override
    public Page<Standard> fandAllAndPage(int page, int rows) {

        //升序排序
        Sort sort = new Sort(Sort.Direction.ASC,"id");

        PageRequest of = PageRequest.of(page-1, rows,sort);
        Page<Standard> pageAll = standardDao.findAll(of);

        return pageAll;
    }

    @Override
    public void standardDel(String ids) {
        //根据","逗号分割
        String[] strs = ids.split(",");
        for (String str : strs) {
            int id = Integer.parseInt(str);
            standardDao.deleteById(id);
        }
    }
}
